# -*- coding: utf-8 -*-
# @Author: QX
# @File: day8_0083m3cmultitouch.py
'''
actions.w3c_actions = ActionBuilder(self.driver, mouse=PointerInput(interaction.POINTER_TOUCH,"touch"))
按下：pointer_down()
抬起：release()
移动：move_to_location()
暂停：pause(时长)
perform()：执行

'''
from appium import webdriver

from selenium.webdriver.common.action_chains import  ActionChains
from selenium.webdriver.common.actions import  interaction
from selenium.webdriver.common.actions.action_builder import  ActionBuilder
from selenium.webdriver.common.actions.pointer_input import  PointerInput

desired_caps = {
    'platformName': 'Android',  # 根据实际情况填写平台名称
    'platformVersion': '12',  # 填写设备的操作系统版本
    'deviceName': 'ba08213e',  # 填写设备名称
    'appPackage': 'com.autonavi.minimap',  # 填写要操作的地图应用包名
    'appActivity': 'com.autonavi.map.activity.NewMapActivity',  # 填写地图应用的启动Activity
    'noReset': True , # 根据需要设置是否重置应用状态
    'automationName': 'uiautomator2'
}

driver = webdriver.Remote('http://127.0.0.1:4723', desired_caps)  # 连接到 Appium 服务器
driver.activate_app('com.autonavi.minimap')
driver.implicitly_wait(30)  # 设置隐式等待时间
def builder_mouse():
    actions = ActionChains(driver)        #定义输入源，声明是触碰操作
    #生成动作链，用鼠标操作--为动作链设置动作构建器，指定鼠标操作类型为触摸操作。
    actions.w3c_actions = ActionBuilder(driver, mouse=PointerInput(interaction.POINTER_TOUCH,"touch"))        #定义动作 按下——》滑动——》抬起
    #获得手机的宽和高
    width=driver.get_window_size()['width']
    height=driver.get_window_size()['height']
    #将鼠标放在手机屏幕的最中心
    actions.w3c_actions.pointer_action.move_to_location(x=width*0.5,y=height*0.5)
    #按下鼠标左键
    actions.w3c_actions.pointer_action.pointer_down()
    #移动到指定的位置
    actions.w3c_actions.pointer_action.move_to_location(355, 176)
    #暂停
    actions.w3c_actions.pointer_action.pause(2)  # todo 暂停2秒
    actions.w3c_actions.pointer_action.move_to_location(595, 176)
    actions.w3c_actions.pointer_action.pause(2)
    actions.w3c_actions.pointer_action.move_to_location(595, 416)
    actions.w3c_actions.pointer_action.pause(2)
    # 最有一个点
    actions.w3c_actions.pointer_action.move_to_location(595, 650)
    # 抬起
    actions.w3c_actions.pointer_action.release()
    # 执行
    actions.perform()